import ajax from './ajax'
const  BASE_URL = 'http://demo.itlike.com/web/xlmc';

export const getHomeData = ()=>ajax(BASE_URL + '/api/homeApi');
export const getCategories = ()=>ajax(BASE_URL + '/api/homeApi/categories');

export const getCategoriesDetail = (preParams)=>ajax(BASE_URL + '/api/homeApi/categoriesdetail'+ preParams);

// 获取短信验证码
export const getPhoneCode = (phone)=>ajax(BASE_URL+"/api/send_code",{phone});
// 登录
export const phoneCodeLogin = (phone,code)=>ajax(BASE_URL+"/api/login_code",{phone,code},'POST');
// 用户名和密码登录(POST)
export const pwdLogin = (user_name, user_pwd, captcha) => ajax(BASE_URL + '/api/login_pwd', {user_name, user_pwd, captcha}, 'POST');
// 2.4 自动登录
export const  getUserInfo = ()=> ajax(BASE_URL + '/api/userinfo');
// 2.5 退出登录
export const getLogOut = ()=> ajax(BASE_URL + '/api/logout');

//3 购物车接口
// 3.1 添加商品到购物车
export const addGoodsToCart = (user_id,goods_id,goods_name,goods_price,small_image)=>ajax(BASE_URL + '/api/cart/add',{user_id,goods_id,goods_name,goods_price,small_image},'POST')
//3.2 获取当前用户购物车商品
export const getGoodsCart = (user_id) =>ajax(BASE_URL +'/api/cart/search'+user_id);
//3.3 添加/删除购物车商品数量
export const changeCartNum = (user_id,goods_id,type)=>ajax(BASE_URL +'api/cart/num',{user_id,goods_id,type},'POST')
//3.4 删除购物车商品
export const clearAllCart = (user_id)=>ajax(BASE_URL +'api/cart/clear' + user_id)

//4 地址接口
// 4.1 获取当前用户的地址
export const getUserAddress = (user_id) => ajax(BASE_URL+ '/api/address/search/'+ user_id);

// 4.2 添加新的地址
export const addUserAddress = ( user_id, address_name, address_phone, address_area, address_area_detail, address_post_code, address_tag, province, city, county, areaCode)=>ajax(BASE_URL + '/api/address/add', {user_id, address_name, address_phone, address_area, address_area_detail, address_post_code, address_tag, province, city, county, areaCode}, 'POST');
// 4.3 编辑用户的地址
export const changeUserAddress = ( address_id, user_id, address_name, address_phone, address_area, address_area_detail, address_post_code, address_tag, province, city, county, areaCode)=>ajax(BASE_URL + '/api/address/edit', {address_id, user_id, address_name, address_phone, address_area, address_area_detail, address_post_code, address_tag, province, city, county, areaCode}, 'POST');
// 4.4 删除用户的地址
export const delUserAddress = (address_id) => ajax(BASE_URL+ '/api/address/del/'+ address_id);
// 4.5 获取单条地址
export const getCurrentUserAddress = ( user_id, address_id)=>ajax(BASE_URL + '/api/address/one', {user_id, address_id}, 'POST');